package Thread;
//sychronized修饰方法
class cunter{
    int count;
    public synchronized void count (){
        //synchronized(this){}
        count++;
    }
//    public static synchronized void count2 (){
//      synchronized(cunter.class){}
//        count++;
//    }
}
public class Demo12 {
    public static void main(String[] args) throws InterruptedException {
        cunter counter=new cunter();
        Thread t1=new Thread(()->{
            for (int i=0;i<50000;i++){
                counter.count();
            }
        });
        Thread t2=new Thread(()->{
            for (int i=0;i<50000;i++){
                counter.count();
            }
        });
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        System.out.println("count="+counter.count);
    }


}
